
 

function get_mediainfo(mediainfoIndex) {
    switch (mediainfoIndex) {        

        case 0:
            return  { "mediaUrl": 			mediaUrl,
                      "placeholderImage": mediaImage,
                      "chapters": [               
                                  ] };
        case 1:
            return  { "mediaUrl": 			downloadMediaUrl,
                      "placeholderImage": mediaImage,
                      "chapters": [               
                                  ] };
                          
        default:
             throw Error.invalidOperation("No such mediainfo");
     }
}

function StartWithParent(parentId, appId) {
    new StartPlayer_0(parentId);
}

function StartPlayer_0(parentId) {

	if (CheckVersion())
	{
		this._hostname = EePlayer.Player._getUniqueName("xamlHost");
		Silverlight.createObjectEx( {   source: playerXaml, 
											parentElement: $get(parentId ||"wpfePlayerHost"), 
											id:this._hostname, 
											properties:{ width:'320px', height:'301px', inplaceInstallPrompt:true, version:'1.0', background:document.body.style.backgroundColor, isWindowless:'true' }, 
											events:{ onLoad:Function.createDelegate(this, this._handleLoad) } } );
		this._currentMediainfo = 0;      
    }
    else
    {
		var parentElement =  $get(parentId ||"wpfePlayerHost");
		var message = 'You appear to have a pre-release version of Silverlight installed (that will not auto-update), please uninstall it and then return to the site to get the current release version.';
		parentElement.innerHTML=message;

    }
}

function CheckVersion()
{
	var version = "1.0";
	var isInstalled = Silverlight.isInstalled(version);
	if (isInstalled)
	{
		version = "1.0.20800.0";

		isInstalled = Silverlight.isInstalled(version);
		
		if (!isInstalled)
		{
			var message = 'You appear to have a pre-release version of Silverlight installed (that will not auto-update), please uninstall it and then return to the site to get the current release version.';
			alert(message);
			
			/*
			var currentURL = window.location;
			
			if (currentURL.indexOf('?') > 0)
				currentURL = currentURL + '&Silverlight=false';
			else
				currentURL = currentURL + '?Silverlight=false';
			
			window.location = currentURL;
			*/	
			return false;
		}
	}
	return true;
}

StartPlayer_0.prototype= {
    _handleLoad: function() {
        this._player = $create(   ExtendedPlayer.Player, 
                                  { // properties
                                    autoPlay    : false, 
                                    volume      : 1.0,
                                    muted       : false
                                  }, 
                                  { // event handlers
                                    mediaEnded: Function.createDelegate(this, this._onMediaEnded),
                                    mediaFailed: Function.createDelegate(this, this._onMediaFailed)
                                  },
                                  null, $get(this._hostname)  ); 
        this._playNextVideo();     
    },    
    _onMediaEnded: function(sender, eventArgs) {
        //window.setTimeout( Function.createDelegate(this, this._playNextVideo), 1000);
    },
    _onMediaFailed: function(sender, eventArgs) {
		window.setTimeout( Function.createDelegate(this, this._playNextVideo), 1000);       
    },
    _playNextVideo: function() {
        var cVideos = 1;
        if (this._currentMediainfo<cVideos)
            this._player.set_mediainfo( get_mediainfo( this._currentMediainfo++ ) );    
    }        
}
